package com.gcsoftware.web.mapper.providers;

import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * Created by qs on 2018/3/25.
 */
public class SysLogProvider {
    public String loginLogSql(@Param(value = "c_LOGIN_NAME") String c_LOGIN_NAME, @Param(value = "c_START_TIME")String c_START_TIME, @Param(value = "c_END_TIME") String c_END_TIME) {
        return new SQL(){{
            SELECT("c_LOG_ID,log.c_USER_ID,usr.C_LOGIN_NAME ,c_LOGIN_IP,to_char(D_LOG_TIME, 'yyyy-MM-dd hh24:mi:ss') c_LOGIN_TIME,c_LOG_STATUS ");
            FROM("T_COM_SYS_LOGS log,T_COM_SYS_USER usr");
            WHERE("usr.C_USER_ID =log.C_USER_ID and log.C_LOG_TYPE ='LOG_TYPE_LOGIN'");
            if (StringUtils.isNotBlank(c_LOGIN_NAME)) {
                WHERE("usr.c_LOGIN_NAME = #{c_LOGIN_NAME}");
            }
            if (StringUtils.isNotBlank(c_START_TIME)) {
                WHERE("log.D_LOG_TIME >= to_timestamp(#{c_START_TIME}, 'yyyy-MM-dd HH24:MI:SS')");
            }
            if (StringUtils.isNotBlank(c_END_TIME)) {
                WHERE("log.D_LOG_TIME <= to_timestamp(#{c_END_TIME}, 'yyyy-MM-dd HH24:MI:SS')");
            }
            ORDER_BY("log.D_LOG_TIME DESC");
        }}.toString();
    }
}
